#!/bin/bash
#chmod u+rwx run.sh
nc -w 10 -z www.baidu.com 80 ##-w设置超时时长10秒
if [ $? -eq 0 ]
then
echo "网络连接正常"
else
echo "网络连接异常,请检查网络连接再重试！"
exit 1
fi

result=$(go version)
echo "result=$result"
if [ -n "$result" ]
then
   echo "已安装go语言运行环境......"
else
   echo "没有安装go语言运行环境，正在安装......"
   wget https://golang.google.cn/dl/go1.18.3.linux-amd64.tar.gz -P /usr/local/src
   rm -rf /usr/local/go && tar -C /usr/local -xzf /usr/local/src/go1.18.3.linux-amd64.tar.gz

   export GOROOT=/usr/local/go 
   export PATH=$PATH:$GOROOT/bin
   export GOPATH=$HOME/go 
   source /etc/profile
   go env -w GOPROXY=https://goproxy.cn,direct

   go get -u -v golang.org/x/net
   go get -u -v github.com/gin-gonic/gin
   go get -u -v github.com/go-ego/gse
   go get -u -v github.com/unrolled/secure
   echo "go语言环境安装成功"
fi
curl localhost:27017
if [ $? -eq 0 ]
then
echo "mongodb已正常"
else
echo "mongodb异常，请安装mongodb"
exit 1
fi

